#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : pythonProject1
@File : porttools.py
@Author : 蓝精灵
@Time : 2025/11/2 19:30  
@脚本说明 : 
"""
import concurrent.futures
import socket


# 真正干活
def port_brute(ip_host, port):
    try:
        tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        tcp_socket.settimeout(0.5)
        result = tcp_socket.connect_ex((ip_host, port))
        if result == 0:
            print(f"[+] {ip_host}:{port} 端口开放")
        tcp_socket.close()
    except:
        pass


# 分配任务
def port_brute_run(ip_host):
    # 创建线程池 max_workers=1000 表示最大线程数 电脑性能可以 可以增加
    with concurrent.futures.ThreadPoolExecutor(max_workers=10000) as executor:
        for port in range(1, 65535):
            executor.submit(port_brute, ip_host, port)
